// miniprogram/pages/test.js
const util = require('../../utils/util.js')
const reptile = require('../../utils/reptile.js')
const reptileWord = require('../../utils/reptileWord.js')
const reptilePhrase = require('../../utils/reptilePhrase.js')
const reptileRoot = require('../../utils/reptileRoot.js')
const reptileArticle = require('../../utils/reptileArticle.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  onLoad: function (options) {
   

    //爬取单词
    //reptileWord.reptileQuery();
    //爬取词组
    //reptilePhrase.reptileQuery();
    //爬取词根
    //reptileRoot.reptileQuery();

    //批量删除
    //this.batchDelete(303);
    
    //爬取文章
    //reptileArticle.reptileQuery();

    // let article = '<p>大家还好吗</p><p>　　更多英语新词，请关注阿卡索线上英语英语官网。如果你在英语学习过程中遇到了困难，也可以寻求英语培训机构老师的帮助哦！</p>';
    // article = article.replace(/<p>([\s\S]*?)(注阿卡索线上*)([\S]*?)<\/p>/g, "");
    // console.info("===article==");
    // console.info(article);
  },
  batchDelete: function (cate) {
    let filter = { category: cate };

    wx.cloud.callFunction({
      name: 'delete',
      data: {
        dbName: 'article_list',
        filter: filter
      },
      success(res) {
        console.info("批量删除");
        console.info(res);
      },
      fail() {
      }
    });
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad_test: function (options) {
    //http://word.qsbdc.com/wl.php?level=2&tag=all&page_id=10

    function refreshQuery() {
      let url = 'http://www.qsbdc.com/ajax/word_measure_server.php?click_id=98117&_=' + new Date().getMilliseconds();
      console.info(url);
      wx.request({
        url: url,
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          let resData = res.data;
          resData = resData.substring(1, resData.length-1);
          reptile.parseWordTestJson(resData);
        }
      })
    }

    setInterval(refreshQuery, 500000000);
  }
})